import React from 'react';
import { inject, observer } from 'mobx-react';
import { toJS } from 'mobx';
import { Button, Row, Col, Modal } from 'antd';
import {
  WeaDialog,
  WeaFormItem,
  WeaDatePicker,
} from 'ecCom';
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
const errorModal = Modal.error;

const store = ['meetingStoreMap','meetingRepeat', 'meetingDialog'];
@inject(...store)
@observer
export default class EndRepeatMeeting extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
    }
  }

  render() {
    const { enddate, repeatenddate, repeatbegindate } = this.props.meetingRepeat;
    //多页面公用，store动态获取处理
    const endRepeatStore = this.props.meetingStoreMap.getMapStore(this.props.storeKey);
    const {dialogStatus} = endRepeatStore;
    const {advanceModal, endRepeatLoading} = dialogStatus;
    const advanceButtons = [
      <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@1lw74l@submit`}
        key="advanceSave"
        type="primary"
        loading={endRepeatLoading}
        text={getLabel(383336,"提交")}
        onClick={this.advanceSubmit}
      >
        {getLabel(383336,"提交")}
      </Button>
    ];

    return (
      <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@io3vow`}
        visible={advanceModal}
        title={getLabel(383447,"提前结束重复会议")}
        icon="icon-coms-meeting"
        iconBgcolor="#f14a2d"
        buttons={advanceButtons}
        style={{ width: '450px', height: '120px' }}
        onCancel={() => { endRepeatStore.advanceModal(false) }}>
        <div className="advance-over-body" style={{ marginTop: '20px' }}>
          <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@z9tk0w`}
            label={getLabel(25903,"重复结束日期")}
            labelCol={{ span: '7', offset: '2' }}
            wrapperCol={{ span: '11' }}>
            <WeaDatePicker ecId={`${this && this.props && this.props.ecId || ''}_WeaDatePicker@w4yovy`}
              style={{width: '100%'}}
              onChange={(e) => this.props.meetingRepeat.setState({ repeatenddate: e })}
              value={repeatenddate}
              startValue={''}
              endValue={enddate}
            />
          </WeaFormItem>
        </div>
      </WeaDialog>
    )
  }

  advanceSubmit = () => {
    const { meetingStoreMap, meetingRepeat } = this.props;
    const { enddate, repeatenddate, repeatbegindate } = meetingRepeat;

    const endRepeatStore = meetingStoreMap.getMapStore(this.props.storeKey);//多页面公用，store动态获取处理
    const { advanceModal, StopIntvl, dialogStatus } = endRepeatStore;
    const { advanceModalparams } = toJS(dialogStatus);
    if (repeatenddate > enddate) {
      errorModal({
        title: getLabel(383337,"无法提交"),
        content: getLabel(383338,"选择的日期只能小于原定重复结束日期"),
      });
    } else if(repeatenddate < repeatbegindate){
        errorModal({
            title: getLabel(383337,"无法提交"),
            content: getLabel(388217,"选择的日期不能小于原定重复开始日期"),
          });
    }else {
      StopIntvl({
        enddate: repeatenddate,
        meetingid: advanceModalparams.meetingid,
      }, (meetingId = advanceModalparams.meetingid) => {
        advanceModal(false);
        this.props.setAll && this.props.setAll(meetingId, true, 'preview');

        //回调刷新查看页面
        const {doInit, getPreview, form} = this.props.meetingDialog;
        doInit('preview', true, meetingId, () => {
          getPreview({meetingid: meetingId }, (conditions) => {
            this.props.doRefesh && this.props.doRefesh();
            form[advanceModalparams.meetingid] && form[advanceModalparams.meetingid].initFormFields(conditions); //结束后刷新查看会议页面
          })})
      })
    }
  }

}
